package ua.org.nuos.sdms.middle.service;

import ua.org.nuos.sdms.middle.entity.Group;
import ua.org.nuos.sdms.middle.entity.UserToGroup;
import ua.org.nuos.sdms.middle.util.exception.DuplicateNameException;
import ua.org.nuos.sdms.middle.util.exception.NotGroupLeaderException;
import ua.org.nuos.sdms.middle.util.exception.OneGroupLeaderException;
import ua.org.nuos.sdms.middle.vo.GroupSearch;

import javax.ejb.Local;
import java.util.List;

/**
 * User: Denis Fahritdinov
 * Date: 10/7/12
 * Time: 11:39 AM
 */
@Local
public interface GroupServiceLocal {

    /**
     * Create new group
     *
     * @param group
     * @throws DuplicateNameException
     */
    void createGroup(Group group) throws DuplicateNameException;

    /**
     * Update existing group
     *
     * @param group
     * @throws DuplicateNameException
     * @throws NotGroupLeaderException
     */
    void updateGroup(Group group) throws DuplicateNameException, NotGroupLeaderException;

    /**
     * Find group by id
     *
     * @param groupId
     * @return
     */
    Group findGroupById(long groupId);

    /**
     * Find group list by group name
     *
     * @param name
     * @return
     */
    List<Group> listGroupsByName(String name);

    /**
     * Find group list by group organisation
     *
     * @param organisation
     * @return
     */
    List<Group> listGroupsByOrganisation(String organisation);

    /**
     * Find group list by user in groups
     *
     * @param userId
     * @return
     */
    List<Group> listGroupsByUser(long userId);

    /**
     * Find group list by GroupSearch(user.name, user.email, group.name, group.org)
     *
     * @param search
     * @return
     */
    List<Group> listGroups(GroupSearch search);

    /**
     * Remove group
     *
     * @param groupId
     * @throws NotGroupLeaderException
     */
    void removeGroup(long groupId) throws NotGroupLeaderException;

    /**
     * Attach current user to existing group
     *
     * @param groupId
     * @param status
     */
    void attachCurrentUserToGroup(long groupId, UserToGroup.Status status);

    /**
     * Attach existing user to group
     *
     * @param userId
     * @param groupId
     * @param status
     * @throws NotGroupLeaderException
     */
    void attachUserToGroup(long userId, long groupId, UserToGroup.Status status) throws NotGroupLeaderException;

    /**
     * Update user status in group
     *
     * @param userId
     * @param groupId
     * @param status
     * @throws NotGroupLeaderException
     * @throws OneGroupLeaderException
     */
    void updateStatus(long userId, long groupId, UserToGroup.Status status) throws NotGroupLeaderException, OneGroupLeaderException;

    /**
     * Update current user status in group
     *
     * @param groupId
     * @param status
     */
    void updateCurrentUserStatus(long groupId, UserToGroup.Status status);

    /**
     * Find user status in group
     *
     * @param userId
     * @param groupId
     * @return
     */
    UserToGroup.Status findStatus(long userId, long groupId);

    /**
     * Find current user status in group
     *
     * @param groupId
     * @return
     */
    UserToGroup.Status findStatus(long groupId);

    /**
     * Remove user from group
     *
     * @param userId
     * @param groupId
     * @throws NotGroupLeaderException
     */
    void removeUserFromGroup(long userId, long groupId) throws NotGroupLeaderException;

    /**
     * Remove current user from group
     *
     * @param groupId
     */
    void removeUserFromGroup(long groupId);
}
